"""天气接口查询"""
import requests

geo_url = "https://restapi.amap.com/v3/geocode/geo"
geo_params = {'key': '58b8527d0f9ed3264778f088c348ccb6', 'address': '上海', 'output': 'JSON'}
# 查询address code
ad_code = requests.get(geo_url, params=geo_params).json().get("geocodes")[0].get("adcode")
print(ad_code)

# 根据 address code 查询天气
weather_url = "https://restapi.amap.com/v3/weather/weatherInfo"
weather_params = {'key': '58b8527d0f9ed3264778f088c348ccb6', 'city': ad_code, 'extensions': 'base', 'output': 'JSON'}

response = requests.get(weather_url, params=weather_params).json().get("lives")[0]

weather = response.get("weather")
temperature = response.get("temperature")
print(weather)
print(temperature)
